import {APPEND_LIST, PREPEND_LIST, SET_SNACKMESSAGE, TOOGLE_SEARCH, TOOGLE_ADVANCESEARCH, SET_SEARCHPARAMS, SET_THUMB, TOOGLE_SWIPE} from './mutation-type'

export default {
  [APPEND_LIST] (state, {params, data}) {
    state[params].data = [...state[params].data, ...data]
  },
  [PREPEND_LIST] (state, {params, data}) {
    state[params].data = [...data, ...state[params].data]
  },
  [SET_SNACKMESSAGE] (state, message) {
    state.common.snackMessage = message
  },
  [TOOGLE_SEARCH] (state) {
    state.common.search.searchEnabled = !state.common.search.searchEnabled
  },
  [TOOGLE_ADVANCESEARCH] (state) {
    state.common.search.advanceSearchEnabled = !state.common.search.advanceSearchEnabled
  },
  [SET_SEARCHPARAMS] (state, {name, value}) {
    for (let key in state.common.search.searchParams) {
      for (let _key in state.common.search.searchParams[key]) {
        if (_key === name) {
          state.common.search.searchParams[key][name] = value
          console.log(value)
        }
      }
    }
  },
  [SET_THUMB] (state, {gid, token, showKey, galleryLength}) {
    state.thumb.thumbList = []
    state.thumb.gid = gid
    state.thumb.token = token
    state.thumb.showKey = showKey
    state.thumb.galleryLength = galleryLength
    for (let i = 1; i <= galleryLength; i++) {
      state.thumb.thumbList.push({
        src: null,
        page: i,
        state: 'pending'
      })
    }
  },
  [TOOGLE_SWIPE] (state) {
    state.common.swipeShow = !state.common.swipeShow
  }
}

